import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import '@/styles/theme.scss'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'

// 配置axios默认值 - 在开发环境下使用代理，不设置baseURL
// axios.defaults.baseURL = 'http://127.0.0.1:5000'
axios.defaults.withCredentials = false

// 添加请求拦截器
axios.interceptors.request.use(
  config => {
    const token = localStorage.getItem('admin_token')
    if (token) {
      config.headers['Authorization'] = `Bearer ${token}`
    }
    return config
  },
  error => {
    return Promise.reject(error)
  }
)

// 动态加载百度地图API
const loadBaiduMap = () => {
  return new Promise((resolve, reject) => {
    if (window.BMap) {
      resolve()
      return
    }
    
    window.initBaiduMap = () => {
      resolve()
    }
    
    const script = document.createElement('script')
    script.src = 'https://api.map.baidu.com/api?v=3.0&ak=Hi4Ddf8yBSFLZUUgxJW1awYf4lAuz0hK&callback=initBaiduMap'
    script.onerror = reject
    document.head.appendChild(script)
  })
}

// 加载百度地图
loadBaiduMap().catch(err => {
  console.warn('百度地图加载失败:', err)
})

const app = createApp(App)

app.use(ElementPlus)
app.use(store)
app.use(router)

app.mount('#app') 